package oj;

public class RemoveElements {
    public ListNode removeElements(ListNode head, int val) {
        if(head == null){
            return head;
        }
        ListNode cur = head;
        ListNode del = head.next;
        while(del != null){
            if(del.val == val){
                cur.next = del.next;
                del = del.next;
            }else{
                cur = del;
                del = del.next;
            }
        }
        if(head.val == val){
            head = head.next;
        }
        return head;
    }
}
